package io.renren.sf.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.sf.vo.CbStiffQuickspotListVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.sf.entity.CbStiffQuickspotEntity;
import io.renren.sf.service.CbStiffQuickspotService;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author cyl_txw
 * @email cyl_txw@gmail.com
 * @date 2021-04-26 10:46:38
 */
@RestController
@RequestMapping("sf/cbstiffquickspot")
public class CbStiffQuickspotController {
    @Autowired
    private CbStiffQuickspotService cbStiffQuickspotService;

    /**
     * 保存List
     */
    @PostMapping("/saveList")
    //@RequiresPermissions("sf:cbstiffquickspot:save")
    public R saveList(@RequestBody CbStiffQuickspotListVo cbStiffQuickspotList){
        CbStiffQuickspotEntity cbStiffQuickspot = new CbStiffQuickspotEntity();
        cbStiffQuickspot.setFlag(cbStiffQuickspotList.getFlag1());
        cbStiffQuickspot.setQuickspotPicture(cbStiffQuickspotList.getQuickspotPicture1());
        cbStiffQuickspot.setTid(cbStiffQuickspotList.getTid());
        cbStiffQuickspot.setErrorReason(cbStiffQuickspotList.getErrorReason1());
        cbStiffQuickspotService.save(cbStiffQuickspot);

        cbStiffQuickspot = new CbStiffQuickspotEntity();
        cbStiffQuickspot.setTid(cbStiffQuickspotList.getTid());
        cbStiffQuickspot.setFlag(cbStiffQuickspotList.getFlag2());
        cbStiffQuickspot.setQuickspotPicture(cbStiffQuickspotList.getQuickspotPicture2());
        cbStiffQuickspot.setErrorReason(cbStiffQuickspotList.getErrorReason2());
        cbStiffQuickspotService.save(cbStiffQuickspot);

        cbStiffQuickspot = new CbStiffQuickspotEntity();
        cbStiffQuickspot.setTid(cbStiffQuickspotList.getTid());
        cbStiffQuickspot.setFlag(cbStiffQuickspotList.getFlag3());
        cbStiffQuickspot.setQuickspotPicture(cbStiffQuickspotList.getQuickspotPicture3());
        cbStiffQuickspot.setErrorReason(cbStiffQuickspotList.getErrorReason3());
        cbStiffQuickspotService.save(cbStiffQuickspot);

        cbStiffQuickspot = new CbStiffQuickspotEntity();
        cbStiffQuickspot.setTid(cbStiffQuickspotList.getTid());
        cbStiffQuickspot.setFlag(cbStiffQuickspotList.getFlag4());
        cbStiffQuickspot.setQuickspotPicture(cbStiffQuickspotList.getQuickspotPicture4());
        cbStiffQuickspot.setErrorReason(cbStiffQuickspotList.getErrorReason4());
        cbStiffQuickspotService.save(cbStiffQuickspot);
        return R.ok();
    }

    /**
     * 更新List
     */
    @PostMapping("/updateList")
    //@RequiresPermissions("sf:cbstiffquickspot:save")
    public R updateList(@RequestBody CbStiffQuickspotListVo cbStiffQuickspotList){
        CbStiffQuickspotEntity cbStiffQuickspot = new CbStiffQuickspotEntity();
        cbStiffQuickspot.setFlag(cbStiffQuickspotList.getFlag1());
        cbStiffQuickspot.setId(cbStiffQuickspotList.getUpdateId1());
        cbStiffQuickspot.setQuickspotPicture(cbStiffQuickspotList.getQuickspotPicture1());
        cbStiffQuickspot.setTid(cbStiffQuickspotList.getTid());
        cbStiffQuickspot.setErrorReason(cbStiffQuickspotList.getErrorReason1());
        cbStiffQuickspotService.updateById(cbStiffQuickspot);

        cbStiffQuickspot = new CbStiffQuickspotEntity();
        cbStiffQuickspot.setTid(cbStiffQuickspotList.getTid());
        cbStiffQuickspot.setFlag(cbStiffQuickspotList.getFlag2());
        cbStiffQuickspot.setId(cbStiffQuickspotList.getUpdateId2());
        cbStiffQuickspot.setQuickspotPicture(cbStiffQuickspotList.getQuickspotPicture2());
        cbStiffQuickspot.setErrorReason(cbStiffQuickspotList.getErrorReason2());
        cbStiffQuickspotService.updateById(cbStiffQuickspot);

        cbStiffQuickspot = new CbStiffQuickspotEntity();
        cbStiffQuickspot.setTid(cbStiffQuickspotList.getTid());
        cbStiffQuickspot.setFlag(cbStiffQuickspotList.getFlag3());
        cbStiffQuickspot.setId(cbStiffQuickspotList.getUpdateId3());
        cbStiffQuickspot.setQuickspotPicture(cbStiffQuickspotList.getQuickspotPicture3());
        cbStiffQuickspot.setErrorReason(cbStiffQuickspotList.getErrorReason3());
        cbStiffQuickspotService.updateById(cbStiffQuickspot);

        cbStiffQuickspot = new CbStiffQuickspotEntity();
        cbStiffQuickspot.setTid(cbStiffQuickspotList.getTid());
        cbStiffQuickspot.setFlag(cbStiffQuickspotList.getFlag4());
        cbStiffQuickspot.setId(cbStiffQuickspotList.getUpdateId4());
        cbStiffQuickspot.setQuickspotPicture(cbStiffQuickspotList.getQuickspotPicture4());
        cbStiffQuickspot.setErrorReason(cbStiffQuickspotList.getErrorReason4());
        cbStiffQuickspotService.updateById(cbStiffQuickspot);
        return R.ok();
    }

    /**
     * 信息
     */
    @GetMapping("/getQuickspotListByTid/{id}")
    //@RequiresPermissions("sf:cbstiffquickspot:info")
    public R getQuickspotListByTid(@PathVariable("id") Long id){
        List<CbStiffQuickspotEntity> cbStiffQuickspots = cbStiffQuickspotService.list(new QueryWrapper<CbStiffQuickspotEntity>().eq("tid", id));

        return R.ok().put("cbStiffQuickspots", cbStiffQuickspots);
    }
    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("sf:cbstiffquickspot:info")
    public R info(@PathVariable("id") Long id){
		CbStiffQuickspotEntity cbStiffQuickspot = cbStiffQuickspotService.getById(id);

        return R.ok().put("cbStiffQuickspot", cbStiffQuickspot);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("sf:cbstiffquickspot:save")
    public R save(@RequestBody CbStiffQuickspotEntity cbStiffQuickspot){
		cbStiffQuickspotService.save(cbStiffQuickspot);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("sf:cbstiffquickspot:update")
    public R update(@RequestBody CbStiffQuickspotEntity cbStiffQuickspot){
		cbStiffQuickspotService.updateById(cbStiffQuickspot);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("sf:cbstiffquickspot:delete")
    public R delete(@RequestBody Long[] ids){
		cbStiffQuickspotService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
